

import * as THREE from 'three';
import IElement from 'components/Three/interface/IElement';
import Controller from 'Controller'
import React from "react";
import { Switch } from 'antd';

export default function CastShadowItem() {

    const threeController = Controller.instance.useMemo(s => s.threeController, []);

    const selectedElementUuid = threeController.useMemo(s => s.selectedElementUuid, []);

    const elementMap = threeController.useMemo(s => s.elementMap, []);

    const element: IElement<THREE.Object3D> | undefined = React.useMemo(() => selectedElementUuid ? elementMap.get(selectedElementUuid) : undefined, [elementMap, selectedElementUuid])

    const onChange = React.useCallback((e: boolean) => {
        if (!element) return;

        threeController.pipeline(async s => {
            element.version++;
            element.object3D.castShadow = e;
        })()

    }, [element, threeController])

    if (!element) return <></>;

    return (
        <Switch onChange={onChange} size="small" checked={element.object3D.castShadow} />
    )
}
